package operation;

import book.BookList;

import java.util.Scanner;

public class DelOperation implements  IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("新删除图书");
        Scanner scanner=new Scanner(System.in);
        System.out.println("输入删除图书名称");
        String name=scanner.nextLine();
        int cur=bookList.getUsedSize();
        for(int i=0;i<cur;i++)
        {
            if(bookList.getBook(i).getName().equals(name))
            {
                for(int j=i;j<cur-1;j++)
                {
                    bookList.setBooks(j,bookList.getBook(j+1));
                }
                bookList.setBooks(cur-1,null);
                bookList.setUsedSize(cur-1);
                System.out.println("删除成功");
                return ;


            }

        }
        System.out.println("未找到该书");
        return;
    }
}